package com.guigu.buy.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guigu.buy.dto.Ord_Pro;
import com.guigu.buy.pojo.OrderDetails;
import com.guigu.buy.service.IOrderDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author com.guigu
 * @since 2024-05-15
 */
@CrossOrigin
@Controller
@RequestMapping("/buy/orderDetails")
public class OrderDetailsController {
    @Autowired
    private IOrderDetailsService orderDetailsService;
    @RequestMapping("/getByParentId/{id}")
    @ResponseBody
    public List<OrderDetails> getByParentId(@PathVariable int id){
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("order_id",id);
        return orderDetailsService.list(wrapper);
    }

    //根据订单编号查询详情订单

    @RequestMapping("/orderdetaid/{id}")
    @ResponseBody
    public List<Ord_Pro> OrderId(@PathVariable int id ) {
        List<Ord_Pro>  list=orderDetailsService.getByParentId(id);
        return list;
    }

    //点击审核（ D001-2(审核通过)）

    @RequestMapping("/passtheaudit/{id}")
    @ResponseBody
    public String passtheaudit(@PathVariable int id) {

        OrderDetails orderDetails = new OrderDetails();
        orderDetails.setBackState("D001-2");
        orderDetails.setId(id);
        boolean flag = this.orderDetailsService.updateById(orderDetails);
        if (flag) {

            return "ok";
        }
        return "error";
    }
}
